import { login } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'
import { Message } from 'element-ui'
const state = {
  token: getToken(),
  count: 0
}

const mutations = {
  setToken(state, payload) {
    state.token = payload
    setToken(payload)
  },
  addCount(state) {
    state.count++
  }

}

const actions = {
  async login(context, payload) {
    const res = await login(payload)
    console.log(res.data)
    Message.success(res.data.message)
    if (res.data.success) {
      console.log('aysnc')
      context.commit('setToken', res.data.data)
    }
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

